﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Daybreak.Core.Rendering.Pipeline;

namespace Daybreak.Core.Rendering.Materials
{
    public class FxMaterial : IMaterial
    {
        FxShader _shader;

        public FxMaterial(FxShader shader)
        {
            _shader = shader;
        }

        public static FxMaterial Compile(string fxFile)
        {
            FxShader shader = FxShader.Compile(fxFile);

            if (shader == null)
                return null;

            return new FxMaterial(shader);
        }

        public override string ToString()
        {
            return string.Format("{0}_material", _shader);
        }

        #region IMaterial Members

        public Shader Effect
        {
            get { return _shader; }
        }

        public string Name
        {
            get { return _shader.Name + "_material"; }
        }

        #endregion

        public void SetTexture(SasSemantic sem, Texture texture, int index)
        {
            Shader.TextureValue prm = _shader.FindParam<Shader.TextureValue>(sem, index);

            if (prm != null)
                prm.Value = texture;
        }
    }
}
